package vcp.views;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import javax.swing.event.AncestorListener;

import client.Message;
import db.parking.beans.rates;
import vcp.common.AbstractView;
import vcp.common.IView;
import vcp.controllers.RatesController;
import vcp.gui.panels.parkingworker.PnlRatesCurrent;

/**
 * Parking Worker Rates View
 *
 */
public class ParkingWorkerRatesView  extends AbstractView implements IView,Observer {
    boolean ratesTableLoaded=false;
	PnlRatesCurrent pnlrates;
    
    public ParkingWorkerRatesView(){
    	pnlrates = new PnlRatesCurrent();
    }
    
	public PnlRatesCurrent getPnlrates() {
		return pnlrates;
	}

	public void setPnlrates(PnlRatesCurrent pnlrates) {
		this.pnlrates = pnlrates;
	}

	@Override
	public void update(Observable arg0, Object arg) {
		Message recvmsg = (Message) arg;		
		if (recvmsg.getMsg().equals("GetRatesByLotNum") && ratesTableLoaded==false) {
			@SuppressWarnings("unchecked")
			ArrayList<rates> list = 
					(ArrayList<rates>) recvmsg.getObj();
			java.util.Iterator<rates> itty = list.iterator();
			Object obj[] = new Object[2];
			while (itty.hasNext()) {
				rates c = (rates) itty.next();
				//obj[0] = c.getLotNo();

				switch(c.getRateType()){
				case 1:
					obj[0] = "Occasional Parking";
					break;
				case 2:
					obj[0] = "One-time parking";
					break;
				case 3:
					obj[0] = "Monthly subscription single car";
					break;
				case 4:
					obj[0] = "Monthly subscription multiple cars";
					break;
				case 5:
					obj[0] = "Complete monthly subscription single car";
					break;
				default:
					obj[0] = "undefined";
					break;
				}
			
				obj[1] = c.getAmount();
				pnlrates.getDtm().addRow(obj);
			}
			ratesTableLoaded=true;
		
	}
		
}

	@Override
	public void addController(Object obj) {
		RatesController controller = (RatesController)obj;
		pnlrates.getTable().addAncestorListener(
				(AncestorListener) controller);
		
		//pnlrates.getTable().getSelectionModel().
        //addListSelectionListener((ListSelectionListener)controller.getTableListselectionListener());
		
		
	}

}
